import Vue from 'vue'
import Router from 'vue-router'
import Home from '@/pages/home/Home'
import City from '@/pages/city/City'
import Detail from '@/pages/detail/Detail'

Vue.use(Router)
Vue.prototype.$setgoindex = function () {
  if (window.history.length <= 1) {
    if (location.href.indexOf('?') === -1) {
      window.location.href = location.href + '?goindex=true'
    } else if (location.href.indexOf('?') !== -1 && location.href.indexOf('goindex') === -1) {
      window.location.href = location.href + '&goindex=true'
    }
  }
}
export default new Router({
  routes: [{
      path: '/',
      name: 'Home',
      meta:{index:0},
      component: Home
    },{
    path: '/city',
      name: 'City',
      meta:{index:1},
      component: City
    },{
    path: '/detail/:id',
      name: 'Detail',
      meta:{index:1},
      component: Detail
    }],
    scrollBehavior (to, from, savedPosition) {
      return { x: 0, y: 0 }
    }
})
